<template>
    <div class="index">
        <el-container>
            <el-header class="header">
                <div class="title">
                    <img src="../assets/image/logo.png" alt="" class="logo">
                    <h2>智慧养老</h2>
                </div>
                <el-breadcrumb>
                    <el-breadcrumb-item>服务管理</el-breadcrumb-item>
                    <el-breadcrumb-item>费用管理</el-breadcrumb-item>
                    <el-breadcrumb-item>统计管理</el-breadcrumb-item>
                    <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                </el-breadcrumb>
                <div class="right">
                    <div class="search">
                        <img src="../assets/image/search.png" alt="">
                        <Search></Search>
                    </div>
                    <div class="news">
                        <img src="../assets/image/bell.png" alt="">
                    </div>
                    <div class="user">
                        <img src="../assets/image/user.png" alt="">
                        <p>admin</p>
                    </div>
                </div>
            </el-header>
            <el-container>
                <el-aside width="236px" style="background-color: #fff">
                    <el-tree 
                        :data="data" 
                        :props="defaultProps" 
                        accordion 
                        @node-click="handleNodeClick">
                    </el-tree>
                </el-aside>
                <el-main >
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import Search from '../components/Search'

export default {
    name: 'Index',
    components: {
        Search
    },
    data() {
        return {
            data: [
                {
                    label: '首页',
                    path: '/index/index',
                }, 
                {
                    label: '接待管理',
                    children: [{
                        label: '接待登记',
                        path: '/index/reception-register', 
                    }, {
                        label: '来访登记',
                        path: '/index/reception-visit',
                    },{
                        label: '老人信息查询',
                        path: '/index/reception-query',
                    },{
                        label: '床位查询',
                        path: '/index/reception-bed', 
                    }]
                }, 
                {
                    label: '评估管理',
                    children: [{
                        label: '能力评估信息登记',
                        path: '/index/assess-registration', 
                    }, {
                        label: '能力评估',
                        path: '/index/assess-evaluation',
                    }]
                },
                {
                    label: '用户管理',
                    children: [{
                        label: '用户档案',
                        path: '/index/user-profile',
                    }, {
                        label: '入院登记',
                        path: '/index/user-admission',
                    },{
                        label: '外出登记',
                        path: '/index/user-outgoing',
                    },{
                        label: '退住登记',
                        path: '/index/user-retirement',
                    }]
                },
                {
                    label: '护理管理',
                    children: [{
                        label: '服务项目管理',
                        path: '/index/care-project',
                    },{
                        label:'护理等级',
                        path: '/index/care-level',
                    },{
                        label: '护理管理',
                        path: '/index/care-staff',
                    },{
                        label: '护理报表',
                        path: '/index/care-record',
                    }]
                },
                {
                    label: '床位管理',
                    children: [{
                        label: '床位管理',
                        path: '/index/bed-management',
                    }, {
                        label: '转床管理',
                        path: '/index/bed-transfer',
                    },{
                        label: '转房管理',
                        path: '/index/bed-move',
                    },{
                        label: '床位设置',
                        path: '/index/bed-setting',
                    }]
                },
                {
                    label: '膳食管理',
                    children: [{
                        label: '膳食类项目管理',
                        path: '/index/food-project',
                    }, {
                        label: '点餐服务',
                        path: '/index/food-service',
                    },{
                        label: '膳食计划',
                        path: '/index/food-plan',
                    },{
                        label: '配送计划',
                        path: '/index/food-delivery',
                    }]
                },
            ],
            defaultProps: {
                children: 'children',
                label: 'label'
            }
        };
    },
    methods: {
        handleNodeClick(node) {
            // 获取当前路由路径
            const currentPath = this.$route.path;

            // 如果节点有路径，执行路由跳转
            if (node.path) {
                // 检查路径是否相同
                if (node.path === currentPath) {
                    // 刷新当前路由（可以通过调用 this.$router.replace 来实现）
                    this.$router.replace({ path: node.path, query: { t: Date.now() } });
                } else {
                    // 路径不同，正常跳转
                    this.$router.push(node.path);
                }
            }
        }
    }
}

</script>

<style>
/* elmentent-ui自带样式 */
.el-header {
    background-color: #fff;
    color: #333;
    text-align: center;
    line-height: 60px;
} 
.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
}
.el-main {
    background-color: #E9EEF3;
    color: #333;
    
} 

/* 自己更改的样式 */
.el-container {
    height: 100vh;
}
.el-tree-node__content {
    height: 46px!important;
    line-height: 46px;
    color: #252525;
}
.menu-icon {
    margin-left: 20px;
    background: url('../assets/image/menu.png');
    background-size: 100% 100%;
}
/* 菜单栏 */
.menu-icon {
    margin-right: 10px;
    width: 18px;
    height: 18px;
}
.header {
    display: flex;
    justify-content: space-between;
}
.title {
    display: flex;
    margin-right: 50px;
    justify-content: center;
}
.logo {
    width: 45px;
    height: 45px;
    margin-right: 10px;
}
.title h2 {
    font-size: 23px;
    color: #000000;
    text-align: center;
    font-weight: 700;
    font-style: normal;
    line-height: 50px;
}
.el-breadcrumb__inner {
    height: 60px;
    line-height: 60px;
}
.el-breadcrumb__inner {
    color: #000!important;
    font-size: 14px;
}
.el-menu li:nth-child(1) i {
    display: none;
}
.el-aside {
    text-align: left;
}
/* 顶部导航 */
.el-breadcrumb__separator {
    display: none;
}
.el-breadcrumb__item {
    cursor: pointer;
}
.el-breadcrumb__item:hover .el-breadcrumb__inner {
    background: #f2f2f2;
}
.el-breadcrumb {
    margin-right: 300px;
}
.el-breadcrumb__inner {
    display: block;
    margin-top: 12px;
    margin-right: 20px;
    width: 86px;
    height: 32px;
    line-height: 32px;
    font-size: 14px;
    color: #000000;
    /* background-color: rgba(231, 245, 255, 1); */
}
.right {
    display: flex;
}
.search {
    width: 235px;
    height: 32px;
    display: flex;
    position: relative;
    top: 15px;
}
.search img {
    width: 16px;
    height: 16px;
    position: absolute;
    left: 37px;
    top: 8px;
    z-index: 3;
}
.search input {
    height: 32px;
}
.search .el-input {
    position: absolute !important;
    top: -15px;
    left: 30px;
}
.el-input__inner {
    padding: 0 30px!important;
}
.news {
    margin-left: 50px;
    line-height: 72px;
}
.news img {
    width: 25px;
    height: 25px;
}
.user {
    display: flex;
    align-items: center;
}
.user img {
    width: 30px;
    height: 30px;
}
</style>